#include "stdafx.h"
#include "QUDP.h"
#include "QMutex.h"
#include "Common.h"
HANDLE ha;

char* GuidToString(const GUID &guid)
{
	static char buf[64] = {0};
	_snprintf(
		buf,
		sizeof(buf),
		"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
		guid.Data1, guid.Data2, guid.Data3,
		guid.Data4[0], guid.Data4[1],
		guid.Data4[2], guid.Data4[3],
		guid.Data4[4], guid.Data4[5],
		guid.Data4[6], guid.Data4[7]
	);
	return buf;
}

BYTE Get_Bit(DWORD dw,BYTE pos)
{
	bitset<32> b(dw);
	return b[pos];
}

DWORD Set_Bit(DWORD dw,BYTE pos,bool b)
{
	bitset<32> bits(dw);
	bits[pos]=b;
	return bits.to_ulong();
}

DWORD ServerThread(LPVOID param)
{

	return 1;
}
DWORD ClientThread(LPVOID param)
{
	WaitForSingleObject(ha,INFINITE);
	cout<<"sssss"<<endl;
	return 1;
}

int _tmain(int argc, _TCHAR* argv[])
{

	ha=CreateEvent(NULL,FALSE,FALSE,"asdf");
//	ResetEvent(ha);
//	CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)ServerThread,NULL,NULL,NULL);
	CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)ClientThread,NULL,NULL,NULL);
	
	//cout<<(int)Get_Bit(2,1);
	cin.get();
	SetEvent(ha);
	
	CreateThread(NULL,NULL,(LPTHREAD_START_ROUTINE)ClientThread,NULL,NULL,NULL);

	cin.get();
	SetEvent(ha);
		cin.get();

	return 0;
}
